<%--
  Created by IntelliJ IDEA.
  User: shen
  Date: 2020/2/14
  Time: 10:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath%>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>填空题查询</title>
    <%@include file="../common_resource.jsp" %>
    <link href="font-awesome/css/font-awesome.css" rel="stylesheet">

    <link href="css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">

    <style type="text/css">
        .main_body{
            /*position: relative;
            top:190px;*/
            font-size: 14px;
        }
        .listDiv{
            font-size: 13px;
        }
    </style>
    <script type="text/javascript">

        $.getJSON('Kld/selectAllLev/0', function (res) {
            var qxid = $('#questCatagory');

            $.each(res, function (index,item) {
                console.log('%i - %o', index, item);
                qxid.append('<option value="' + item.levKldID +'">' + item.levKldCtgr + '</option>');
            })
        });


        // 加二级知识点下拉列表
        function changeLevKld(ele) {
            var  levKldID= ele.options[ele.selectedIndex].value;
            $.getJSON('Kld/selectAllSecByLevID/0',{levKldID:  levKldID},function (res) {
                var secKldID = $('#secKldID');
                secKldID.empty();
                $.each(res, function (index,item) {
                    console.log('%i - %o', index, item);
                    secKldID.append('<option value="' + item.secKldID +'">' + item.secKldCtgr + '</option>');
                })
            });
        }
    </script>
    <script type="text/javascript">

        //把编程题异步添加到考卷
        function addtOExam(){
            var FormData = $("#searchForm").serialize();
            $("#addExamMsg").empty();
            $.post("examination/insertExamZZY.do",FormData,function(json){
                if(json.num > 0){
                    $("#addExamMsg").append("加入试卷成功");
                }else{
                    $("#addExamMsg").append("加入试卷失败");
                }

            },"json");
        }


        function to(){
            location.href="views/question/single_input.jsp";
        }
        function checkAll(){
            var box=document.getElementsByName("selectID");
            var chkall=document.getElementById("checkall");
            if(chkall.checked){
                for(var i=0;i<box.length;i++){
                    box[i].checked=true;
                }
            }else{
                for(var i=0;i<box.length;i++){
                    box[i].checked=false;
                }
            }
        }

        function doUpdate(id){
            location.href='question/selectSQuestionById.do?id='+id;

        }

        function detail(id){
            var o = document.getElementById("option"+id);
            if (o){
                if (o.style.display == "none"){ o.style.display = "block"; } else {o.style.display = "none";}
            }


            $.get("question/selectQuestionById.do",{"id":id},function(json){
                $.each(json, function(i,item){
                    $("#optionA"+id).html(item.optionA);
                    $("#optionB"+id).html(item.optionB);
                    $("#optionC"+id).html(item.optionC);
                    $("#optionD"+id).html(item.optionD);
                });

            });
        }


        function collapseExpand(ss){
            $(ss).style.display = "block";
        }

        function doDelete(id){
            $("#delOKModal").modal();
            $("#OKBtn").click(function(){
                $("#OKBtn").attr("data-dismiss","modal");
                $.get("question/deleteQuestionById.do",{"id":id},function(json){
                    if(json.flag == 1){
                        $("#question"+id).remove();
                        $("#delSuccessModal").modal();
                    }else{
                        $("#delFeildModal").modal();
                    }
                });
            });
        }

        function insertExam(){
            var FormData = $("#searchForm").serialize();
            $.post("examination/insertExamZZY.do",FormData,function(json){
                if(json.num > 0){
                    $("#addExamMsg").append("加入试卷成功");
                }else{
                    $("#addExamMsg").append("加入试卷失败");
                }

            },"json");
        }


        function openOption(){
            var obj=document.getElementsByName('selectID');
            for(var i=0; i<obj.length; i++){
                var id=obj[i].value;
                $.get("question/selectQuestionById.do",{"id":id},function(json){
                    $.each(json, function(i,item){
                        $("#optionA"+item.questionId).html(item.optionA);
                        $("#optionB"+item.questionId).html(item.optionB);
                        $("#optionC"+item.questionId).html(item.optionC);
                        $("#optionD"+item.questionId).html(item.optionD);
                        $("#optionE"+item.questionId).html(item.optionE);
                    });
                });
                var o = document.getElementById("option"+id);
                if (o){
                    if (o.style.display == "none"){ o.style.display = "block";$("#openlog").html("[-]"); } else {o.style.display = "none"; $("#openlog").html("[+]");}
                }
            }

        }
        $(function(){
            <c:if test="${not empty updateRdiolag and updateRdiolag}">
            $("#successModal").modal();
            </c:if>

            <c:if test="${not empty updateRdiolag and (not updateRdiolag)}">
            $("#feildModal").modal();
            </c:if>

            <c:if test="${not empty savaRdiolag and savaRdiolag}">
            $("#insertSuccessModal").modal();
            </c:if>

            <c:if test="${not empty savaRdiolag and (not savaRdiolag)}">
            $("#insertFailModal").modal();
            </c:if>
        });
    </script>
    <c:remove var="savaRdiolag" scope="session"/>
    <c:remove var="updateRdiolag" scope="session"/>

</head>
<body class="main_body">
<div class="container container-1180" >
    <div class="col" style="margin-top: 10px;">
        <div class="panel panel-info">
            <div class="panel-heading">
                <span ><i class="fa fa-user"></i></span> <label><font style="font-weight: bold;margin-left: 10px;font-size: 17px">查&nbsp;询&nbsp;填&nbsp;空&nbsp;题</font></label>
                <label style="float: right;">
                    <div class="button_bar">
                        <button class="btn btn-info btn-sm" onclick="to()">继续新增</button>
                    </div>
                </label>
            </div>
            <form id="searchForm" name="searchForm" role="form"   action="question/selectAllFQuestions/0" method="post">
                <!-- 试题类型 -->
                <!-- 查询 -->
                <input type="hidden" name="coll_exp" value="0" />
                <table border="0" width="100%" >
                    <tr>
                        <td width="15px" rowspan="2"></td>
                        <td>
                            <fieldset style="margin-top: 10px;border-color: #BCE8F1">
                                <div id="searchDiv" style="margin-left:210px;margin-top: 10px">
                                    <div class="input-group">
                                        <span class="input-group-addon">	<label><strong>填空题题干：</strong></label></span>
                                        <input type="text" name="question"  style="width: 290px" class="form-control" placeholder="请输入模糊题干查询"/>
                                    </div><br/>
                                    <div style="float:left;">
                                        <label>&nbsp;难度(请单击选择)</label>
                                        <select id="difficulty" name="difficulty"   size="7"  style="width:120px;" class="easyui-validatebox form-control"  >
                                            <option value="0.25">0.25</option>
                                            <option value="0.5">0.5</option>
                                            <option value="0.75">0.75</option>
                                        </select>
                                        <br/><br/>
                                    </div>
                                    <div style="float:left;">
                                        <label>&nbsp;一级知识点(请单击选择)</label>
                                        <label id="questCtgrError" class="catagoryMsg"></label>

                                        <label style="margin-left: 80px">&nbsp;二级知识点(可多选)</label></br>
                                        <select id="questCatagory"  name="levKldID"  size="8" style="margin-left:10px;width:200px;" onchange="changeLevKld(this)">

                                        </select>

                                        <select id="secKldID" size="8" name="secKld" style="width:120px;" multiple="multiple">
                                            <option>--不限--</option>
                                        </select>
                                        <br/>
                                    </div>

                                    <div style="clear:both;width:500px;"></div>
                                    <div class="list-query-button">
                                        <input id="sbm" type="submit" value="查询" class="btn btn-info"/>&nbsp;&nbsp;&nbsp;&nbsp;
                                        <input type="reset" value="重置" class="btn btn-warning" />
                                    </div>

                                </div>

                            </fieldset>

                        </td>
                        <td width="20px" rowspan="2"></td>
                    </tr>
                    <tr>
                        <td >
                            <!-- 列表 -->

                            <div class="listDiv">
                                <c:set var="idno" value="${1+page.pageNum*10 }" scope="page"/>
                                <c:forEach var="fQlist" items="${fQuestionList }" >
                                    <div id="question${fQlist.fQuestionID }" class="panel panel-info" style="font-size: 13px;">
                                        <div class="paner-body panel-heading" >
                                            <input  type="checkbox"   name="selectID" value="${fQlist.fQuestionID }"/>
                                            <label style="color: black;">&nbsp;</label>

                                            <a id="questionBody"
                                               href="javascript:detail(${fQlist.fQuestionID });">${idno}.${fQlist.sdfsQuestions.question }(${fQlist.sdfsQuestions.difficulty})</a>
                                        </div>
                                        <div id="option${fQlist.fQuestionID}" class="file-list panel-collapse collapse" style="display: none;">
                                            <span class="answer">答案：${fQlist.fCorrect }</span>
                                            <span style="margin-left:20px;">
				  		                        <input type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#doUpdateSQ" data-backdrop="static" value="更新"
                                                     onclick="doUpdate(${fQlist.fQuestionID});"></input>
                                                <input type="button" class="del btn btn-danger btn-sm" value="删除" fQuestionID="${fQlist.fQuestionID}" style="margin-right:20px;"></input>
				  	                        </span>
                                        </div>
                                    </div>
                                    <c:set var="idno" value="${idno+1  }" scope="page"/>
                                    <div style="height: 10px"></div>
                                </c:forEach>

                                <!-- 展开试题部分 -->
                                <div class="add_exam">
                                    <div class="panel panel-info">
                                        <div class="panel-heading" role="tab" id="headingTwo">
                                            <h4 class="panel-title">
                                                <a href="javascript:return false;" style="text-decoration:none;" title="全部展开/全部收起 选项">
                                                    <span id="openlog" onclick="openOption();" class="collapse_expand">[+]</span>
                                                </a>
                                                <input type="checkbox" id="checkall" onclick="checkAll();"/>&nbsp;&nbsp;全选/不全选<br /><br />
                                            </h4>
                                        </div>
                                    </div>


                                <br />
                            </div>
                            <!-- 分页 -->
                            <div class="pager" style="padding-left:50px;background-color: #FAEBD7">
                                <%--分页显示--%>
                                    总${fQuestionList.getTotal()}条 &nbsp;&nbsp; 第${fQuestionList.getPageNum()}页/共${fQuestionList.getPages()}页
                                    &nbsp;&nbsp; &nbsp;&nbsp;
                                    <c:if test="${fQuestionList.getPageNum() gt 1}">
                                        <a href="question/selectAllFQuestions/1">第一页</a> &nbsp;
                                    </c:if>
                                    <c:if test="${fQuestionList.getPageNum() gt 1}">
                                        <a href="question/selectAllFQuestions/${fQuestionList.getPageNum()-1}">上一页</a>&nbsp;
                                    </c:if>

                                    <c:if test="${fQuestionList.getPageNum() lt fQuestionList.getPages()}">
                                        <a href="question/selectAllFQuestions/${fQuestionList.getPageNum()+1}">下一页</a>&nbsp;
                                    </c:if>
                                    <c:if test="${fQuestionList.getPageNum() lt fQuestionList.getPages()}">
                                        <a href="question/selectAllFQuestions/${fQuestionList.getPages()}">末页</a>&nbsp;
                                    </c:if>

                            </div>
                        </td>
                    </tr>
                </table>

            </form>
        </div>
    </div>
</div>
<%--更新操作的模态框--%>
<div class="modal fade" tabindex="-1" role="dialog" id="doUpdateSQ">
    <div class="modal-dialog" role="document">
        <div class="modal-content">

        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script src="bootstrap/plugins/transition.js"></script>
<script src="bootstrap/plugins/modal.js"></script>
<script src="bootstrap/plugins/tooltip.js"></script>
<script src="bootstrap/plugins/popover.js"></script>
<script src="bootstrap/plugins/collapse.js"></script>
<script src="bootstrap/js/jquery.editable-select.min.js"></script>
<script src="js/jquery-2.0.0.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
<!-- Mainly scripts -->
<script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="js/plugins/slimscroll/jquery.slimscroll.min.js"></script>

<!-- Custom and plugin javascript -->
<script src="js/inspinia.js"></script>
<script src="js/plugins/pace/pace.min.js"></script>

<!-- Sweet alert -->
<script src="js/plugins/sweetalert/sweetalert.min.js"></script>

<!-- JavaScript Test -->
<script type="text/javascript">

    // 将表单加入到模态框中显示，查询显示需要更新的数据
    function doUpdate(fQuestionID) {

        // 在加入表单到模态框前先清除模态框内之前的表单
        $('#doUpdateSQ .modal-content').empty();

        $.get('question/selectSdfsQuestionsByID/3',{fQuestionID: fQuestionID},function (res) {
            console.log(res);
            $('#doUpdateSQ .modal-content').append(res);
        })
    }

    // 更新保存
    function updateSave(fQuestionID) {
        //console.log("123");
        // 序列化表单，将表单输入框的值封装成：empno=7369&ename=SMITH&job=CLERK&job=7902&hiredate=1980-12-17&sal=5900.0&comm=100.0&deptno=20
        var data = $('#updateSdfsQ').serialize();
        //console.log(data);
        $.post('question/updateDfshQ',data,function (res) {
            if (res.updateDfshQ){
                // 手动关闭模态框
                $('#doUpdateSQ').modal('hide');
                $('#doUpdateSQ .modal-content').empty();
                swal({
                    title: "更新试题",
                    text: "更新"+fQuestionID+"的试题信息成功",
                    type: "success"
                },function () {
                    location.reload();
                });

            } else {
                swal({
                    title: "更新试题",
                    text: "更新"+fQuestionID+"的试题信息失败，请重新检查",
                    type:"error"
                });
            }
        },'json')

    }

    // 删除弹出框
    $('.del').click(function () {

        // 获取属性值
        var fQuestionID=$(this).attr('fQuestionID');
        swal({
                title: "你确定删除"+fQuestionID+"试题信息?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的，删除它！",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                closeOnCancel: false },
            function (isConfirm) {
                if (isConfirm) {
                    // 通过get发送信息到doDelete
                    $.get('question/deleteSdfsQ/3',{sdfsQuestionID:fQuestionID},
                        function (res) {
                            if (res.deleteSdfsQ){
                                //console.log(res.result);
                                $('#question'+fQuestionID).remove();
                                swal("删除", "该试题"+fQuestionID+"信息已经被删除", "success");
                            }else{
                                swal("警告", "该试题"+fQuestionID+"信息不能被删除", "error");
                            }
                        },'json')

                } else {
                    swal("取消", "该试题"+fQuestionID+"信息删除操作被取消)", "error");
                }
            });
    });



    $(function(){
        $('#editable-select').editableSelect({
            effects: 'slide'
        });
        $('.js-popover').popover();
        $('.js-tooltip').tooltip();
        $('#tall-toggle').click(function(){
            console.log(555);
            $('#tall').toggle();
        });


    });
</script>
</body>
</html>

